home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / demos / contempo / microhel / heapchk / heapchk.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-10-06  |  6.8 KB  |  196 lines

  1. VERSION 2.00
  2. Begin Form fHeapChk 
  3.    Caption         =   "HeapWalker Comparison"
  4.    ClientHeight    =   3615
  5.    ClientLeft      =   3705
  6.    ClientTop       =   3405
  7.    ClientWidth     =   7425
  8.    Height          =   4020
  9.    Left            =   3645
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3615
  12.    ScaleWidth      =   7425
  13.    Top             =   3060
  14.    Width           =   7545
  15.    Begin CommandButton cmdProcess 
  16.       Caption         =   "&Process"
  17.       Height          =   495
  18.       Left            =   345
  19.       TabIndex        =   7
  20.       Top             =   2925
  21.       Width           =   1215
  22.    End
  23.    Begin CommandButton cmdClose 
  24.       Cancel          =   -1  'True
  25.       Caption         =   "&Close"
  26.       Height          =   465
  27.       Left            =   5865
  28.       TabIndex        =   6
  29.       Top             =   2985
  30.       Width           =   1215
  31.    End
  32.    Begin TextBox txtOutput 
  33.       Height          =   300
  34.       Left            =   3075
  35.       TabIndex        =   2
  36.       Text            =   "D:\TEMP\HWDUMP.TXT"
  37.       Top             =   1485
  38.       Width           =   2460
  39.    End
  40.    Begin TextBox txtAfter 
  41.       Height          =   315
  42.       Left            =   3075
  43.       TabIndex        =   1
  44.       Text            =   "D:\MSVC\BIN\HWG01.TXT"
  45.       Top             =   795
  46.       Width           =   2475
  47.    End
  48.    Begin TextBox txtBefore 
  49.       Height          =   315
  50.       Left            =   3060
  51.       TabIndex        =   0
  52.       Text            =   "D:\MSVC\BIN\HWG00.TXT"
  53.       Top             =   120
  54.       Width           =   2475
  55.    End
  56.    Begin Label lblMisc 
  57.       Alignment       =   1  'Right Justify
  58.       Height          =   270
  59.       Index           =   4
  60.       Left            =   4065
  61.       TabIndex        =   9
  62.       Top             =   2115
  63.       Width           =   855
  64.    End
  65.    Begin Label lblMisc 
  66.       Caption         =   "Processing Line:"
  67.       Height          =   270
  68.       Index           =   3
  69.       Left            =   2355
  70.       TabIndex        =   8
  71.       Top             =   2130
  72.       Width           =   1590
  73.    End
  74.    Begin Label lblMisc 
  75.       Caption         =   "Output File:"
  76.       Height          =   270
  77.       Index           =   2
  78.       Left            =   1680
  79.       TabIndex        =   5
  80.       Top             =   1530
  81.       Width           =   1215
  82.    End
  83.    Begin Label lblMisc 
  84.       Caption         =   "After File:"
  85.       Height          =   270
  86.       Index           =   1
  87.       Left            =   1620
  88.       TabIndex        =   4
  89.       Top             =   825
  90.       Width           =   1215
  91.    End
  92.    Begin Label lblMisc 
  93.       Caption         =   "Before File:"
  94.       Height          =   270
  95.       Index           =   0
  96.       Left            =   1620
  97.       TabIndex        =   3
  98.       Top             =   150
  99.       Width           =   1215
  100.    End
  101. 'HeapCheck - by TBO/MicroHelp, Inc.
  102. 'this program is nothing fancy - it was written originally for in-house use
  103. 'so our Muscle product is used for expediency.  You can replace the two Muscle
  104. 'routines used with VB code if you want to modify this program and do not
  105. 'have Muscle.  If you don't have Muscle, you will NOT be able to run this
  106. 'in the VB IDE
  107. 'Suggestion - before doing a "Before" dump, make Windows as clean as possible
  108. 'by unloading everything but your shell.  Do the "Before" snapshot, load your
  109. 'application, then do the "After" snapshot.
  110. 'If you do a snapshot after the target app has been unloaded and compare it against
  111. 'the original before, you will normally find several items in the dump file, this
  112. 'is normal and is caused by Windows moving segments.  You will need to look at this
  113. 'output closely to see if the application is "dirty" and left some trash behind.
  114. 'The file names have been hard-coded for simplicity - you can easily change
  115. 'them to your defaults
  116. DefInt A-Z      'Always a good idea
  117. Option Explicit 'you should get used to this as well
  118. Declare Function MhFileExists% Lib "Muscle.vbx" (ByVal FileSpec$)
  119. Declare Function MhFileSearch& Lib "Muscle.vbx" (ByVal CaseSens%, Start&, Search$, ByVal File$)
  120. Dim isCancel    'bool - cancel flag
  121. Sub cmdClose_Click ()
  122.     'not sophisticated, but it works
  123.     If cmdClose.Caption = "&Cancel" Then
  124.         isCancel = True
  125.     Else
  126.         Unload Me
  127.     End If
  128. End Sub
  129. Sub cmdProcess_Click ()
  130.     'if this was something other than a simple program, all code would be in a module
  131.     'vs this form
  132.     ProcessFiles
  133. End Sub
  134. Sub ProcessFiles ()
  135.     'compares file in txtAfter to txtBefore and puts all lines not found in txtOutput
  136.     'since this routine uses MhFileSearch, it will also log any lines that have changed
  137.     'vs only those that are only new / additional
  138.     'minimal error checking provided
  139.     Dim sAfter As String
  140.     Dim sBefore As String
  141.     Dim sOutput As String
  142.     Dim sInput As String
  143.     Dim lStart As Long
  144.     Dim lLineCount As Long
  145.     'since we used Defint A-Z - no need for data type, just Dim for option explicit
  146.     Dim iAfterHandle
  147.     Dim iOutputHandle
  148.     Dim iZero
  149.     Dim iCaseSens
  150.     isCancel = False
  151.     If Not (MhFileExists(txtBefore.Text)) Or Not (MhFileExists(txtAfter.Text)) Then
  152.         MsgBox "Incorrect file name"
  153.     Else
  154.         'Open the after file and read in one line at a time, comparing it to the before file
  155.         On Error GoTo ErrProcessFiles
  156.         'accessing control properties is slower than accessing strings, so store any properties used more than once
  157.         sBefore = txtBefore.Text
  158.         sAfter = txtAfter.Text
  159.         sOutput = txtOutput.Text
  160.         iAfterHandle = FreeFile
  161.         Open sAfter For Input As iAfterHandle
  162.         iOutputHandle = FreeFile
  163.         Open sOutput For Output As iOutputHandle
  164.         cmdClose.Caption = "&Cancel"
  165.         cmdProcess.Enabled = False
  166.         Do Until EOF(iAfterHandle)
  167.             Line Input #iAfterHandle, sInput     'read in a line from the after file
  168.             lLineCount = lLineCount + 1
  169.             lblMisc(4).Caption = Str$(lLineCount)
  170.             DoEvents
  171.             If isCancel Then Exit Do
  172.             If MhFileSearch(iCaseSens, lStart, sInput, sBefore) <= iZero Then
  173.                 'if less than zero, it's not in the file
  174.                 Print #iOutputHandle, sInput    'save it in our output file
  175.             End If
  176.         Loop
  177.         cmdClose.Caption = "&Close"
  178.         cmdProcess.Enabled = True
  179.         Close iAfterHandle
  180.         Close iOutputHandle
  181.         If FileLen(sOutput) = iZero Then
  182.             'they're identical - kill the zero length file
  183.             Kill sOutput
  184.             MsgBox "No Differences in the files!?"
  185.         Else
  186.             MsgBox "Done!"
  187.         End If
  188.     End If
  189.     Exit Sub
  190. ErrProcessFiles:
  191.     cmdClose.Caption = "&Close"
  192.     cmdProcess.Enabled = True
  193.     MsgBox "File I/O Error"
  194.     Exit Sub
  195. End Sub
  196.